package com.stu.controller;

import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author MI
 * @ClassName DeepController.java
 * @createTime 2021年11月26日 09:28:00
 */
@Slf4j
@Api(tags = "二维数组")
@RestController
@RequestMapping("/deeparr")
public class DeepController {
    /**
     * 测试生成 /echarts area-pieces的数据结构
     * data: [
     * ['2019-10-18', 100],
     * ['2019-10-19', 300],
     * ['2019-10-20', 400],
     * ['2019-10-21', 100],
     * ['2019-10-10', 200],
     * ['2019-10-11', 560],
     * ['2019-10-12', 750],
     * ['2019-10-13', 580],
     * ['2019-10-14', 250],
     * ['2019-10-15', 300],
     * ['2019-10-16', 450],
     * ['2019-10-17', 300]
     * <p>
     * ]
     */
    @ApiOperation(value = "测试二维数组", notes = "测试二维数组")
    @GetMapping({"/"})
    public AreaPiecesVO map() {
        AreaPiecesVO piecesVO = new AreaPiecesVO();
        piecesVO.setDateStr("2021-11-26");
        piecesVO.setNum(1);
        return piecesVO;
    }

    @ApiOperation(value = "测试二维数组", notes = "测试二维数组")
    @GetMapping({"/arr"})
    public List<AreaPiecesVO> deep() {
        ArrayList list = new ArrayList<>();
        AreaPiecesVO piecesVO = new AreaPiecesVO();
        piecesVO.setDateStr("2021-11-26");
        piecesVO.setNum(1);
        list.add(piecesVO.getArr());

        AreaPiecesVO areaPiecesVO = new AreaPiecesVO();
        areaPiecesVO.setNum(2);
        areaPiecesVO.setDateStr("2021-11-25");
        list.add(areaPiecesVO);
        return list;
    }

    public static void main(String[] args) {
        AreaPiecesVO piecesVO = new AreaPiecesVO();
        piecesVO.setDateStr("2021-11-26");
        piecesVO.setNum(1);
        System.out.println(piecesVO);
        System.out.println(JSON.toJSONString(piecesVO));

    }

    @Getter
    @Setter
    public static class AreaPiecesVO {
        private String dateStr;
        private Integer num;

        public Object[] getArr() {
            return new Object[]{dateStr, num};
        }

        @Override
        public String toString() {
            return Arrays.toString(new Object[]{dateStr, num});
        }
    }
}
